package com.blog.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by 青水零 on 2022/07/11
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    /**
     * 插入更新时的填充策略
     *
     * @param metaObject meta
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }



    /**
     * 更新时的填充策略
     *
     * @param metaObject meta
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}